import {filedownloadList,filedownloadDelete,downloadFile,queryDownloadStrategy,setDownloaded} from '@/services/workspace';

export default {
  namespace: 'downloadModel',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm: {},

  },

  effects: {

//  查询下载列表
    * filedownloadList({payload}, {call, put}) {
      const response = yield call(filedownloadList, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'save',
        payload: response,
      });
      }
    },
    * setDownloaded({payload}, {call, put}) {
      const response = yield call(setDownloaded, payload);
    },
    * filedownloadDelete({payload, callback}, {call, put}) {
      const response = yield call(filedownloadDelete, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveDelete',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * downloadFile({payload, callback}, {call, put}) {
      const response = yield call(downloadFile, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveDownloadFile',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    * downloadStrategy({payload, callback}, {call, put}) {
      const response = yield call(queryDownloadStrategy, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveDownloadStrategy',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    }
    ,
  }
  ,
}
;
